package com.littlespider.myhabacus.fragments;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.littlespider.myhabacus.R;
import com.littlespider.myhabacus.adapters.FirstPageAdapter;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;
import com.zhouwei.mzbanner.holder.MZViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by littlespider on 2018/10/10.
 */
public class HomeFragment extends BaseFragment {

    @BindView(R.id.barView) View barView;
    @BindView(R.id.banner)
    MZBannerView bannerView;
    @BindView(R.id.recyclerview)
    RecyclerView recyclerView;

    List<Integer> images = new ArrayList<>();

    @Override
    protected int setLayoutRes() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView() {
        ViewGroup.LayoutParams params = barView.getLayoutParams();
        params.height = getStateBar3();
        Log.i("prince", "height:" + params.height);
        barView.setLayoutParams(params);
        images.add(R.drawable.bannar);
        images.add(R.drawable.bannar);
        images.add(R.drawable.bannar);
        images.add(R.drawable.bannar);
        bannerView.setPages(images, new MZHolderCreator<BannerHolder>() {
            @Override
            public BannerHolder createViewHolder() {
                return new BannerHolder();
            }
        });

        recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        recyclerView.setAdapter(new FirstPageAdapter(getActivity()));
        recyclerView.setNestedScrollingEnabled(false);
    }

    @Override
    protected void initData() {

    }

    static class BannerHolder implements MZViewHolder<Integer>{

        private ImageView imageView;

        @Override
        public View createView(Context context) {
            View view = LayoutInflater.from(context).inflate(R.layout.view_image, null);
            imageView = view.findViewById(R.id.imageView);
            return view;
        }

        @Override
        public void onBind(Context context, int i, Integer integer) {
            imageView.setImageResource(integer);
        }
    }
}
